package com.cn.mmd.controller;

import com.cn.mmd.model.LogManage;
import com.cn.mmd.service.InformationService;
import com.cn.mmd.service.LogManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 管理资料
 * Created by Administrator on 2016/8/3 0003.
 */
@Controller
@RequestMapping(value = "page/manageInformation")
public class ManageInformationController {

    @Autowired
    private LogManageService logManageService;

    @Autowired
    private InformationService informationService;

    /**
     * 删除资料
     * @param request
     * @return
     */
    @RequestMapping(value = "/del")
    @ResponseBody public synchronized  Object manageInformationDel(HttpServletRequest request){
        Map<String,Object> objectMap = new HashMap<String, Object>();
        String manageId = request.getParameter("manageId");
        Integer informationId= Integer.parseInt(request.getParameter("informationId"));
        if (informationService.deleteByPrimaryKey(informationId)>0){
            informationService.deleteByInfId(informationId);
            objectMap.put("code", 200);
            objectMap.put("message", "成功");
            Date date = new Date();
            SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String logTime=time.format(date);
            LogManage logManage = new LogManage();
            logManage.setLogtime(logTime);
            logManage.setManageid(manageId);
            logManage.setLogcontent("删除了一份资料:"+informationId);
            logManageService.insertSelective(logManage);
        }else {
            objectMap.put("code", 201);
            objectMap.put("message", "删除失败");
        }
        return objectMap;
    }
}
